package com.demo.alllearning.common.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Mybatis-Plus配置
 *
 * @author yueyang
 * @since 2021-03-08 22:48:00
 */
@Configuration
public class MybatisPlusConfig {

  /**
   * 开启乐观锁配置
   *
   * @return 乐观锁拦截器
   */
  @Bean
  public OptimisticLockerInterceptor optimisticLockerInterceptor() {
    return new OptimisticLockerInterceptor();
  }

  /**
   * 处解决查询时有数据但Page对象total为0的问题
   *
   * @return 分页拦截器
   */
  @Bean
  public PaginationInterceptor paginationInterceptor() {
    PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
    // 配置数据库类型
    paginationInterceptor.setDbType(DbType.MYSQL);
    return paginationInterceptor;
  }
}
